<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<script type="text/javascript">
$(document).ready(function(){
	//메인 이미지 클릭시 팝업 열기
	$("#r_uploadFile").click(function(){
		window.open("${initParam.root }/recipe/imgPopup.jsp","","width=605,height=470,left=400,top=230");
	});
	//처음 4페이지에 접속시 // 새로운 페이지 생성시에
	/* <![CDATA[  */						
	if((${sessionScope.recipeD==null }) || (${requestScope.orderSize<requestScope.order})){
	/* ]]> */
		$("#main_subject_text").css("background-image","url(${initParam.root}/img/main/main-write4-subject.gif)");
		$("#main_content_text").css("background-image","url(${initParam.root}/img/main/main-write4-content.gif)");
	}else{
		$("#r_uploadFile").attr("src","${initParam.root }/upload/temp/${sessionScope.recipeD[order-1].r_img_new}");
		$("#main_subject_text").css("background-image","none");
		$("#main_content_text").css("background-image","none");
	}
	// 글을 쓸 때에 배경글자를 없에준다.
	$("#main_subject_text").focus(function(){
		$("#main_subject_text").css("background-image","none");
	});
	$("#main_content_text").focus(function(){
		$("#main_content_text").css("background-image","none");
	});
	
	//다음버튼
	$("#main_arrow_next").click(function(){
		// null 값 체크
		if($("#main_subject_text").val()==""){
			alert("주제를 입력해주세요");
			return false;
		}
		if($("#r_img_origin").val()==""){
			alert("사진을 등록하세요");
			return false;
		}
		if($("#main_content_text").val()==""){
			alert("상세과정을 입력해주세요");
			return false;
		}
		
		/* <![CDATA[ */																				
		if((${sessionScope.recipeD==null }) || (${requestScope.orderSize<requestScope.order})){
		 /* ]]> */
		 	$("input[name=isNewPage]").val("true");
			$("#pForm_4").submit();
		}else{
		 	$("input[name=isNewPage]").val("false");
			$("#pForm_4").submit();
		}
	});
	// 이전버튼
	$("#main_arrow_prev").click(function(){
		if(${requestScope.order==1}){
			location.href="recipe.do?command=writePrev&page=3";
		}else{
			location.href="recipe.do?command=writeDescPrev";
		}
	});
	//완료 전송버튼
	$("#main_ok").click(function(){
		// null 값 체크
		if($("#main_subject_text").val()==""&&$("#r_img_origin").val()==""&&$("#main_content_text").val()=="" ||$("#main_subject_text").val()!=""&&$("#r_img_origin").val()!=""&&$("#main_content_text").val()!=""){
			if(confirm("전송하시겠습니까?")){
				$("input[name=command]").val("write_submit");
				$("#pForm_4").submit();
			}
		}else{
			alert("내용이 전체 빈값이거나,전부다 채워야 등록됩니다!");
		}
	});
	// 작성 취소 버튼
	$("#main_cancle").click(function(){
		if(confirm("작성을 취소하시겠습니까?")){
			location.href="recipe.do?command=write_cancle";
		}
	});
});

</script>
<div id="write_container">
<!-- 공통부분 -->
<div id="main_page1"><img src="${initParam.root }/img/main/main-write4-ing.gif"></div>
<div id="main_arrow_prev"><input type="image" src="${initParam.root }/img/main/main-write-prev.gif"></div>
<div id="main_arrow_next"><input type="image" src="${initParam.root }/img/main/main-write-next.gif"></div>
<div id="main_info_next"><img src="${initParam.root }/img/main/main-write-next-info.gif"></div>
<div id="main_info_prev"><img src="${initParam.root }/img/main/main-write-prev-info.jpg"></div>
<div id="main_cancle"><input type="image" src="${initParam.root }/img/main/main-write-cancle.gif"></div>
<!-- 여기부턴 이 페이지에서만 쓰임 -->
<div id="main_ok"><input type="image" src="${initParam.root }/img/main/main-write-ok.jpg"></div>
<div id="main_confirm"><input type="text" id="main_confirm_text" value="${requestScope.order+3}" readonly="readonly"></div>
	<div id="main_write_form">
		<!-- 데이터 전송용 폼 -->
 		<form id="pForm_4" action="recipe.do" method="post">
 			<input type="hidden" name="command" value="writeDescNext">
 			<input type="hidden" name="isNewPage" value="">
 			<input type="hidden" name="r_img_origin" id="r_img_origin" value="${sessionScope.recipeD[order-1].r_img_origin}">
 			<input type="hidden" name="r_img_new" id="r_img_new" value="${sessionScope.recipeD[order-1].r_img_new}">
 			<input type="hidden" name="r_img_thum" id="r_img_thum" value="${sessionScope.recipeD[order-1].r_img_thum}">
 			<div id="main_title"><input type="text" id="main_subject_text" name="r_subject" value="${sessionScope.recipeD[order-1].r_subject}"/></div>
 			<div id="main_img" align="center"><img src="${initParam.root }/img/main/main-write-img2.jpg" name="r_uploadFile" id="r_uploadFile" style="cursor: pointer;"></div>
 			<div id="main_comment"><textarea id="main_content_text" cols="75" rows="7" name="r_content">${sessionScope.recipeD[order-1].r_content}</textarea></div>
		 </form>
 	</div>
</div>